<template>
    <div>
        病房号：
        <input type="text" v-model="fan.name" >
        科室:  
        <select v-model="fan.id">
                        <option value="">请选择</option>
                        <option :value="o.kid" v-for="o in Ken">{{ o.kName }}</option>
                    </select>
        <input type="button" value="查询" @click="Show" >
        
        <table>
            <thead>
                <tr>
                    <td>科室名称</td>
                    <td>所属科室</td>
                    <td>科室人数</td>
                    <td>科室描述</td>
                    <td>创建日期</td>
                    <td>功能</td>
                </tr>

                <tr v-for="o in info"  >
                    <td>{{ o.fName }}</td>
                    <td>{{ o.kName }}</td>
                    <td>{{ o.kCount }}</td>
                    <td>{{ o.kText }}</td>
                    <td>{{ moment(o.kDate).format("yyyy-MM-DD") }}</td>
                    <td><input type="button"  value="删除" @click="Update(o.fid)" >
                        <input type="button"  value="修改" @click="date(o.fid)" >
                        </td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';

const router=useRouter();

const date=(fid:any)=>{
    router.push({
        path:"/fandk",
        query:{
            id:fid
        }
    })
}




onMounted(()=>{
    List();
    Show();
})

let Ken:any=ref([]);

const List=()=>{
    axios({
        url:"https://localhost:7030/api/User/ListK",
        method:'get',
    })

    .then((res)=>{
        console.log(res);
        Ken.value=res.data;
    })
}

let fan:any=ref({
    name:'',
    id:''
});
let info:any=ref([]);

const Show=()=>{
    axios({
        url:"https://localhost:7030/api/User/ShowK",
        method:'post',
        params:fan.value
    })

    .then((res)=>{
        console.log(res);
        info.value=res.data;
    })
}

const Update=(fid:any)=>{
    let f=confirm("要删除吗");
    if(f)
{
    axios({
        url:"https://localhost:7030/api/User/UpDatK",
        method:'post',
        params:{
            id:fid,
        }
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0)
    {
        alert("删除成功");
        Show();
    }
    } )
}
    
}



</script>

<style scoped>

</style>